/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sessionbean;

import entity.Cancion;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author bbaquero
 */
@Stateless
public class CancionFacade implements CancionFacadeRemote {
    @PersistenceContext
    private EntityManager em;

    public void create(Cancion cancion) {
        em.persist(cancion);
    }

    public void edit(Cancion cancion) {
        em.merge(cancion);
    }

    public void remove(Cancion cancion) {
        em.remove(em.merge(cancion));
    }

    public Cancion find(Object id) {
        return em.find(Cancion.class, id);
    }

    public List<Cancion> findAll() {
        return em.createQuery("select object(o) from Cancion as o").getResultList();
    }

    public List<Cancion> findByAlbum(Integer album){
       return em.createNamedQuery("Cancion.findByIdAlbum").setParameter("idAlbum", album).getResultList();
    }


}
